package com.hrp.service;

import com.hrp.domain.Menus;
import com.hrp.hrpdao.MenusDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/3 0003.
 */
@Service
public class MenusService {

    @Autowired
    private MenusDao menusDao;


    public List<Menus> getMenus(String username){
        return getMenusByParentId(username,0);
    }


    public List<Menus> getMenusByParentId(String username,Integer parentId){
        //List<Menus> listMenus = new ArrayList<>();
        List<Menus> listMenus = menusDao.getMenus(username,parentId);
        for(Menus menu:listMenus){
            List<Menus> listItem = menusDao.getMenus(username,menu.getId());
            menu.setChildren(listItem);
        }
        return listMenus;
    }

}
